package com.zephyr.vchcenter.bpm.action;

import org.apache.log4j.Logger;
import org.springframework.context.ApplicationContext;

import com.hiaward.bpm.action.GuideAction;
import com.hiaward.bpm.context.Parameter;
import com.hiaward.bpm.context.ServiceContext;
import com.hiaward.bpm.exception.ParameterException;
import com.hiaward.bpm.exception.ServiceException;
import com.hiaward.framework.taskmanage.service.Service;
import com.zephyr.vchcenter.bean.Transfer;
import com.zephyr.vchcenter.bean.Voucher;
import com.zephyr.vchcenter.bpm.util.RandomUtil;
import com.zephyr.vchcenter.dao.IBaseDao;
import com.zephyr.vchcenter.dao.IVoucherDao;
import com.zephyr.vchcenter.dao.impl.VoucherDaoImpl;
import com.zephyr.vchcenter.helper.SpringHelper;
public class CreateVoucherAction extends GuideAction {
	private final Logger log=Logger.getLogger(CreateVoucherAction.class);
	@Override
	public void perform(ServiceContext arg0) throws ServiceException,
			ParameterException {
		log.debug("进入CreateVoucherAction......................");
	    //arg0.getToken().getProcessInstance().getContextInstance().setVariable("WEB_PROCESS_NAME", "WebProcessVchzms");
		String accno=(String)arg0.getInputParameterValue("accno");
		String vchno=(String)arg0.getInputParameterValue("vchno");
		String vchtype=(String)arg0.getInputParameterValue("vchtype");
		String vchdate=(String)arg0.getInputParameterValue("vchdate");
		String amount=(String)arg0.getInputParameterValue("amount");
		String fimgid=(String)arg0.getInputParameterValue("fimgid");
		String bimgid=(String)arg0.getInputParameterValue("bimgid");
		String exchno=(String)arg0.getInputParameterValue("exchno");
		Long processInstanceId=arg0.getToken().getProcessInstance().getId();
		/*log.debug(accno+"--------------");
		log.debug(fimgid+"------++--------");
		log.debug(exchno+"--------------");
		log.debug(bimgid+"-----+++---------");*/
		log.debug(processInstanceId+"-+++--+++---------");
		 RandomUtil randomUtil=new RandomUtil();
		Voucher voucher=new Voucher();
		Transfer transfer=new Transfer();
		
	  /*  String accno="200200";
	    String amount="131223231";//randomUtil.getRandomString(10000);
	   String vchno=randomUtil.getRandomString(10000);
	    String vchtype=randomUtil.getRandomString(10);
	    String vchdate="2008-01-06";
	    String vsbank=randomUtil.getRandomString(1000);//
	    String brbank="1111";//
	    
	   String vchpwd=randomUtil.getRandomString(1000000);
		//Voucher voucher=new Voucher();
	   
	    String exchno="111111111";//randomUtil.getRandomString(1000000);
	    //String vchsid=randomUtil.getUUID();
*/
		String subno="beijing";
		String vchsid=randomUtil.getUUID();
		voucher.setAccno("100100");
	    voucher.setAmount("00000000000000");
	    voucher.setVchno(vchno);
	    voucher.setVchsid(vchsid);
	    voucher.setVchtype(vchtype);
	    //voucher.setVchpwd(vchpwd);
	    voucher.setVchdate(vchdate);
	    voucher.setBrbank("333");
	    //voucher.setVsbank(vsbank);
	    //voucher.setVchsid(vchsid);
	    voucher.setSubno(subno);
	    voucher.setAcctype("1");
	    voucher.setVchdate("2009-01-09");
	    voucher.setExchno(exchno);
	    //voucher.setIdstate(1);
	    voucher.setChkstate("1");
	    voucher.setTallytype("1");
	    //以下是财政户信息
	    /*transfer.setFinaid("123132132");
	    transfer.setVchsid(vchsid);
	    transfer.setIfamount(randomUtil.getRandomString(10));
	    transfer.setPayamount("00000000000000");
	    transfer.setPayinst(randomUtil.getRandomString(100000000));
	    transfer.setPaymode(randomUtil.getRandomString(10));
	    transfer.setPaytype(randomUtil.getRandomString(10));
	    transfer.setPayvchno(vchno);
	    transfer.setSigntype(randomUtil.getRandomString(100000));
	    transfer.setVchchar(randomUtil.getRandomString(100000));*/
	   // voucher.setProcessInstanceId(processInstanceId);
	    IBaseDao dao = (IBaseDao) SpringHelper.getBean("baseDao");
	    dao.saveOrUpdate(voucher);
	    //IBaseDao dao1 = (IBaseDao) SpringHelper.getBean("baseDao");
	    //dao1.saveOrUpdate(transfer);
	    //
	    arg0.setOutputParameterValue("accno", accno);
	    arg0.setOutputParameterValue("amount", amount);
	    arg0.setOutputParameterValue("vchtype", vchtype);
	    //arg0.setOutputParameterValue("vchdate", vsbank);
	    //arg0.setOutputParameterValue("vchpwd", brbank);
	   // log.debug(vchsid);
	    arg0.setOutputParameterValue("vchsid", vchsid);
	    arg0.setOutputParameterValue("vchno", vchno);
	    arg0.setOutputParameterValue("exchno", exchno);
	   // log.debug(":"+vchsid);
	    //arg0.setOutputParameterValue("idstate", "4");
	    //arg0.setOutputParameterValue("chkstate","4");
        log.debug("离开CreateVoucherAction..............."); 
	}
	@Override
	public void serviceExceptionHandle(ServiceContext arg0,
			ServiceException arg1) {
	

	}

}
